package cn.ilikes.webs.services;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import cn.ilikes.modules.likes.dbs.IlikesUser;
import cn.ilikes.modules.likes.modules.users.IUserService;
import cn.ilikes.modules.likes.modules.users.IlikesUserException;

@Component(IWebUserService.SPRING_SERVICE)
public class WebUserService implements IWebUserService {

	@Resource(name = IUserService.SPRING_SERVICE)
	private IUserService moduleUserinfoService;

	@Override
	public int login(String userId, String passwd) {
		try {
			IlikesUser userInfo = moduleUserinfoService.getIlikesUser(passwd);
			if (userInfo == null)
				return IWebUserService.LOGIN_ERROR_NOT_FIND_USER;
			if (userInfo.getPassword().equals(passwd)) {
				return IWebUserService.LOGIN_SUCCESS;
			} else {
				return IWebUserService.LOGIN_ERROR_USER_PASSWD_ERROR;
			}
		} catch (IlikesUserException e) {
			return IWebUserService.LOGIN_ERROR_SYSTEM_ERROR;
		}
	}

}
